package com.ztgf.shopping.api.client.shop;

import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.user.models.dto.UserInfoDTO;
import com.ztgf.user.models.service.IUserInfoService;
import com.ztgf.user.models.vo.UserInfoRoleRelationVO;
import com.ztgf.user.models.vo.UserInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import com.ztgf.shopping.models.service.shop.IShopUserRelationService;
import com.ztgf.shopping.models.bo.shop.ShopUserRelationBO;
import com.ztgf.shopping.models.dto.shop.ShopUserRelationDTO;

/**
 * 店员表控制器
 *
 * @author zhanghualang
 * @Date 2020-05-28 14:43:23
 */

@RestController
@RequestMapping("/api/shopUserRelation")
@Slf4j
@Api(value = "ShopUserRelationApiController",tags = "店员表Api接口")
public class ShopUserRelationApiController {

    @DubboReference
    private IShopUserRelationService shopUserRelationService;

    @DubboReference
    private IUserInfoService iUserInfoService;

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<ShopUserRelationDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        ShopUserRelationDTO dto = shopUserRelationService.selectById(id);

        return new Result<>(dto);
    }

    @PostMapping("/getShopRole")
    @ApiOperation(value = "根据店铺ID获取店铺主账号权限ID",notes = "根据店铺ID获取店铺主账号权限ID")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<Long> getShopRole(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        Long roleId = shopUserRelationService.getRoleByShop(id);

        return new Result<>(roleId);
    }

    @ApiOperation(value = "店员表列表",notes = "店员表列表")
    @PostMapping("/queryPageList")
    public Result<Page<UserInfoRoleRelationVO>> queryPageList(ShopUserRelationBO bo){

        Page<UserInfoRoleRelationVO> page = iUserInfoService.queryUserPageList(bo);

        return new Result<>(page);
    }
    @ApiOperation(value = "是否为主账号",notes = "是否为主账号")
    @PostMapping("/isMainCount")
    public Result<UserInfoDTO> isMainCount(Long id){

        UserInfoDTO userInfoDTO = iUserInfoService.selectById(id);

        return new Result<>(userInfoDTO);
    }
}
